package com.heima.article.controller;

import com.heima.article.dto.ArticleDto;
import com.heima.article.dto.ArticleHomeDto;
import com.heima.article.dto.ArticleInfoDto;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.heima.article.service.IApArticleService;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章信息表，存储已发布的文章 前端控制器
 * </p>
 * @author syl
 * @since 2022-06-29
 */
@RestController
@RequestMapping("/api/v1/article")
@Api(tags = "文章信息表，存储已发布的文章接口")
@CrossOrigin
public class ApArticleController{

    @Autowired
    private IApArticleService apArticleService;

    @PostMapping
    public ResponseResult<Long> saveApArticle(@RequestBody ArticleDto dto){
        return apArticleService.saveApArticle(dto);
    }

    @PostMapping("/load")
    @ApiOperation(value = "load" ,notes = "首页初次加载文章")
    @ApiModelProperty(name = "dto" ,dataType = "ArticleHomeDto" ,required = true)
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,0);
    }

    @PostMapping("/loadnew")
    @ApiOperation(value = "loadnew" ,notes = "首页加载更新文章")
    @ApiModelProperty(name = "dto" ,dataType = "ArticleHomeDto" ,required = true)
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,0);
    }

    @PostMapping("/loadmore")
    @ApiOperation(value = "loadmore" ,notes = "首页加载更多文章")
    @ApiModelProperty(name = "dto" ,dataType = "ArticleHomeDto" ,required = true)
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,1);
    }

    @PostMapping("/load_article_info")
    @ApiOperation(value = "loadArticleInfo" ,notes = "根据id查看文章")
    @ApiModelProperty(name = "dto" ,dataType = "ArticleInfoDto" ,required = true)
    public ResponseResult loadArticleInfo(@RequestBody ArticleInfoDto dto){
        return apArticleService.loadArticleInfo(dto);
    }
}